/*
 * Copyright (C) 2015 wxcx Inc. All rights reserved.
 */
package net.soulwolf.test.poidemo;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * author: Ewen
 * since : 15/11/16 上午10:35.
 */
public class FileUtils {

    @SuppressWarnings("unused")
    private static final boolean DEBUG = true;
    @SuppressWarnings("unused")
    private static final String LOG_TAG = "FileUtils:";

    /**
     * 将html文件保存到sd卡
     * */
    public static void writeFile(String content, File file) {
        FileOutputStream fos = null;
        BufferedWriter bw = null;
        try {
            if(!file.exists()){
                file.createNewFile();
            }
            fos = new FileOutputStream(file);
            bw = new BufferedWriter(new OutputStreamWriter(fos,Constants.DEFAULT_ENCODING));
            bw.write(content);
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            try {
                if (bw != null)
                    bw.close();
                if (fos != null)
                    fos.close();
            } catch (IOException ie) {
            }
        }
    }
}
